package com.labrocante;

// Generated 3 janv. 2014 11:01:57 by Hibernate Tools 3.4.0.CR1

import java.util.List;

import javax.naming.InitialContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import static org.hibernate.criterion.Example.create;

/**
 * Home object for domain model class Annonce.
 * @see com.labrocante.Annonce
 * @author Hibernate Tools
 */
public class AnnonceHome {

	private static final Log log = LogFactory.getLog(AnnonceHome.class);

	public void persist(Annonce transientInstance) {
		log.debug("persisting Annonce instance");
		try {
			Session session = HibernateUtils.getSessionFactory().getCurrentSession();
			session.getTransaction().begin();
			session.persist(transientInstance);
			session.getTransaction().commit();
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}
	
	public Annonce findById(int id) {
		log.debug("getting Annonce instance with id: " + id);
		try {
			Session session = HibernateUtils.getSessionFactory().getCurrentSession();
			session.getTransaction().begin();
			Annonce instance = (Annonce)session.get(Annonce.class, id);
			session.getTransaction().commit();
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}



	public void delete(Annonce persistentInstance) {
		log.debug("deleting Annonce instance");
		try {
			
			Session session = HibernateUtils.getSessionFactory().getCurrentSession();
			session.getTransaction().begin();
			session.delete(persistentInstance);
			session.getTransaction().commit();

			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
}
